// 对这个方法中的参数以及返回值做类型约束
// import type { Recordable,ViteEnv} from '@/types/global.d.ts'

import { Recordable, ViteEnv } from "@/types/global"

// 用来获取当前.env配置文件中的参数的
export function warppEnv(envConf:Recordable):ViteEnv{
  // console.log(envConf,'envConf')
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const ret:any = {}
  for(const envName of Object.keys(envConf)){
    let realName = envConf[envName].replace(/\\n/g,'\n')
    realName = realName === 'true' ? true : realName === 'false' ? false : realName

    if(envName === 'VITE_PORT'){
      realName = Number(realName)
    }
    if(envName === 'VITE_PROXY'){
      try{
        realName = JSON.parse(realName)
      }catch(error){
        console.log(error)
      }
    }
    ret[envName] = realName
    process.env[envName] =  realName

  }
  // console.log(ret,'ret')
  return ret
}